Sorting tab delimited text file based on multiple columns in natural way [duplicate]

Posted by Vignesh on Stack Overflow See other posts from Stack Overflow or by Vignesh
Published on 2014-06-12T15:20:44Z Indexed on 2014/06/12 15:24 UTC
Read the original article Hit count: 258

Filed under:
|
|
|
|

This question already has an answer here:

I am trying to sort a file based on all two columns

Eg:


chr19 1070019 1070020
chr16 869712 869713
chr1 1378131 1378132
chr12 189386 189387
chr4 254941 254942
chr16 1476500 1476501
chr2 1476810 1476811
chr19 313283 313284
chr17 595817 595818
chr18 656897 656898
chr19 1061829 1061830

I Tried sort -t $\t -k1,1 2,2 <filename> but doesn't work.

I want the output to be sorted by first column and second column based on first column. I want to do a natural sort. Not lexical sorting.

Eg:


chr1 1378131 1378132
chr2 1476810 1476811
chr4 254941 254942
chr12 189386 189387
chr16 869712 869713
chr16 1476500 1476501
chr17 595817 595818
chr18 656897 656898
chr19 313283 313284
chr19 1061829 1061830
chr19 1070019 1070020

Anyone any idea?

© Stack Overflow or respective owner

Related posts about linux

Related posts about bash